package com.czk.gulimall.cart.config;

import com.czk.gulimall.cart.interceptor.CartInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/3/12 11:00
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private CartInterceptor cartInterceptor;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("success");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器
        registry.addInterceptor(cartInterceptor).addPathPatterns("/**");
    }
}
